﻿using System;
using System.Data;
using System.Collections.Generic;
using Royalsoft.Common;
using NJL.Model;
using NJL.DALFactory;
using NJL.IDAL;
namespace NJL.BLL
{
	/// <summary>
	/// 支持类型：1：商户
	/// </summary>
	public partial class NJL_REG_SUPPORT
	{
		private readonly INJL_REG_SUPPORT dal=DataAccess.CreateNJL_REG_SUPPORT();
		public NJL_REG_SUPPORT()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_REG_SUPPORT model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_REG_SUPPORT model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			
			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_REG_SUPPORT GetModel(string ID)
		{
			
			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public NJL.Model.NJL_REG_SUPPORT GetModelByCache(string ID)
		{
			
			string CacheKey = "NJL_REG_SUPPORTModel-" + ID;
			object objModel = Royalsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ID);
					if (objModel != null)
					{
						int ModelCache = Royalsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Royalsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (NJL.Model.NJL_REG_SUPPORT)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<NJL.Model.NJL_REG_SUPPORT> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NJL.Model.NJL_REG_SUPPORT> GetModelList(int Top,string strWhere,string Order)
        {
            DataSet ds = dal.GetList(Top,strWhere,Order);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
		/// 获得数据列表
		/// </summary>
        public List<NJL.Model.NJL_REG_SUPPORT> DataTableToList(DataTable dt)
        {
            List<NJL.Model.NJL_REG_SUPPORT> modelList = new List<NJL.Model.NJL_REG_SUPPORT>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NJL.Model.NJL_REG_SUPPORT model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new NJL.Model.NJL_REG_SUPPORT();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = dt.Rows[n]["ID"].ToString();
                    }
                    if (dt.Rows[n]["SUPPORT_OBJECT_TYPE"] != null && dt.Rows[n]["SUPPORT_OBJECT_TYPE"].ToString() != "")
                    {
                        model.SUPPORT_OBJECT_TYPE = int.Parse(dt.Rows[n]["SUPPORT_OBJECT_TYPE"].ToString());
                    }
                    if (dt.Rows[n]["SUPPORT_OBJECT_ID"] != null && dt.Rows[n]["SUPPORT_OBJECT_ID"].ToString() != "")
                    {
                        model.SUPPORT_OBJECT_ID = dt.Rows[n]["SUPPORT_OBJECT_ID"].ToString();
                    }
                    if (dt.Rows[n]["IP"] != null && dt.Rows[n]["IP"].ToString() != "")
                    {
                        model.IP = dt.Rows[n]["IP"].ToString();
                    }
                    if (dt.Rows[n]["CREATE_DATE_TIME"] != null && dt.Rows[n]["CREATE_DATE_TIME"].ToString() != "")
                    {
                        model.CREATE_DATE_TIME = DateTime.Parse(dt.Rows[n]["CREATE_DATE_TIME"].ToString());
                    }
                    if (dt.Rows[n]["SUPPORT_TYPE_CODE"] != null && dt.Rows[n]["SUPPORT_TYPE_CODE"].ToString() != "")
                    {
                        model.SUPPORT_TYPE_CODE = int.Parse(dt.Rows[n]["SUPPORT_TYPE_CODE"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
        /// <summary>
        /// 地方特色想买不想买
        /// </summary>
        /// <param name="typeId"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        public object GetListCount(string typeId, string Id,string supportTypeId)
        {
            return dal.GetListCount(typeId, Id, supportTypeId);
        }
	}
}

